/**
 * main JavaScript
 */
// 日期
$('.week').html(week);
$('.date').html(dates);
mui.init()

var $top = $('.xbzx-table-content').offset().top,
	$rem = $('.mui-content').attr('data-rem'),
	$deviceH = localStorage.getItem('$deviceH'),
	$content = $deviceH - $top - (0.24 * $rem);
//console.log($top)
//console.log($content)
$('.xbzx-table-content').css({
	"height": $content
})
$('.mui-scroll-wrapper').css({
	"height": $content,
	"top": $top,
	"left": 0.6 * $rem,
	"right": 0.6 * $rem,
	"width": "auto"
})
// 新开页面的宽度和左偏移
var $contentW = localStorage.getItem('$contentW'),
	$menuLeftW = localStorage.getItem('$menuLeftW');
// vue 页面数据请求及功能操作方法
var vm = new Vue({
	el: '#content',
	data: {
		dataObj: {}
	},
	mounted: function() {
		this.init()
	},
	methods: {
		init: function() { // 页面初始化  获取预警信息的列表数据
			mui.plusReady(function() {
				var currentView = plus.webview.currentWebview(); // 获取 当前webview
				currentView.show('slide-in-right', 300); // 显示当前webview (方式,时间)
				plus.nativeUI.closeWaiting(); // 关闭系统 loading 等待框

				window.addEventListener('refresh', function(event) {
					location.reload();
				});



				var token = plus.storage.getItem('token');
				mui.ajax(rutour.warn.lists + token, {
					dataType: 'json',
					type: 'post',
					data: {
						pageSize: 5 // 需求设定 mian 页面只显示5条预警信息
					},
					success: function(data) {
						//console.log(data)
						if(data.code == 200) {
							vm.dataObj = data.data;
							mui.toast(data.msg);
							// 初始化区域滚动
							mui('.mui-scroll-wrapper').scroll({
								indicators: false, //是否显示滚动条
								deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
							});
						} else {
							mui.toast(data.msg)
						}
					},
					error: function(type) {
						console.log('网络/服务器出现错误，请稍后重试！');
					}
				})
			})
		},
		openWin: function(urlName) { // 新开页面
			var nwaiting = plus.nativeUI.showWaiting();
			webviewShow = plus.webview.create(urlName, urlName, {
				left: $menuLeftW,
				width: $contentW,
			});
		},
		openbarcode: function(urlName) {
			var nwaiting = plus.nativeUI.showWaiting();
			webviewShow = plus.webview.create(urlName, urlName);
		}
	}
})